package com.shujia.scala

object Demo7Exactpion {
  def main(args: Array[String]): Unit = {


    try {
      //val i: Int = 100 / 0
      //抛出异常
      throw new RuntimeException("运行时异常")
    } catch {

      //匹配异常类型
      case e: ArithmeticException =>
        println("除0异常")
        //打印异常的堆栈信息
        e.printStackTrace()

      case e: RuntimeException =>
        println("运行时异常")
        e.printStackTrace()

    } finally {
      println("都会执行")
    }


    println("代码结束")

  }
}
